
clear
set more off
program drop _all

local owndir = "" // put your path here

global dirdata = "`owndir'/Raw_Data"
global dirin = "`owndir'/Dta"
global dirout = "`owndir'/Output"

// Graphs 1: Cases

use "$dirin/covid19_Seoul_cum_cases_14_by_district.dta",clear
gen year=2020
gen all_dates=mdy(month,day,year)
format all_dates %td

gcollapse (min) min=cum_cases_14 (max) max=cum_cases_14 (mean) cum_cases_14 (sd) sd=cum_cases_14 (p90) p90=cum_cases_14 (p10) p10=cum_cases_14, by(all_dates) fast 

#delimit
twoway 
(scatter cum_cases_14 all_dates, mstyle(p1) mcolor(black))
(rcap p10 p90 all_dates, lstyle(ci))
, tlabel(10feb2020  10mar2020 10apr2020 10may2020, format(%d)) 
leg(order(1 "Mean" 2 "95 percent confidence interval") region(lwidth(none))) leg(off)
ytitle("Total # of confirmed cases for past two weeks") xtitle(" ")
graphregion(color(white)) plotregion(fcolor(white));
#delimit cr	
graph export "$dirout/Figure2a.png", replace


// Graphs 2: Visits

use "$dirin/covid19_Seoul_cum_visits_14_by_district.dta",clear
gen year=2020
gen all_dates=mdy(month,day,year)
format all_dates %td

gcollapse (min) min=cum_visits_14 (max) max=cum_visits_14 (mean) cum_visits_14 (sd) sd=cum_visits_14 (p90) p90=cum_visits_14 (p10) p10=cum_visits_14, by(all_dates) fast 

#delimit
twoway 
(scatter cum_visits_14 all_dates, mstyle(p1) mcolor(black))
(rcap min max all_dates, lstyle(ci))
, tlabel(10feb2020  10mar2020 10apr2020 10may2020, format(%d)) 
leg(order(1 "Mean" 2 "95 percent confidence interval") region(lwidth(none))) leg(off)
ytitle("Total # of visits by confirmed cases for past two weeks") xtitle(" ")
graphregion(color(white)) plotregion(fcolor(white));
#delimit cr	
graph export "$dirout/Figure2b.png", replace

// Graph 3: Correlation

use "$dirin/covid19_Seoul_cum_cases_14_by_district.dta",clear
merge 1:1 month day district using "$dirin/covid19_Seoul_cum_visits_14_by_district.dta"
gen year=2020
gen all_dates=mdy(month,day,year)
format all_dates %td

#delimit
twoway (scatter cum_cases_14 cum_visits_14, msymbol(Oh) mcolor(gs11)) 
(lfit cum_cases_14 cum_visits_14, lcolor(black) lwidth(thick))  
, 
ytitle("Cases for past two weeks") xtitle("Visits for past two weeks") leg(off)
graphregion(color(white)) plotregion(fcolor(white));
#delimit cr	
graph export "$dirout/Figure2c.png", replace
